package cn.usian.basicInformation.sensitivewords.controller;


import cn.usian.basicInformation.log.commons.Constants;
import cn.usian.basicInformation.log.commons.Log;
import cn.usian.basicInformation.sensitivewords.service.ISensitiveWordsService;
import cn.usian.dto.basicInformation.sensitivewords.BaseSensitiveWordsDto;
import cn.usian.pojo.Result;
import cn.usian.pojo.basicInformation.sensitivewords.BaseSensitiveWords;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sensitiveWords")
public class SensitiveWordsController {
    @Autowired
    private ISensitiveWordsService sensitiveWordsService;

    @GetMapping("/list")
    public Result getSensitiveWordsList(BaseSensitiveWordsDto sensitiveWords){
        PageInfo<BaseSensitiveWords> sensitiveWordsList = sensitiveWordsService.list(sensitiveWords);
        return Result.ok(sensitiveWordsList);
    }

    //@PostMapping("/save")
    //public Result save(@RequestBody BaseSensitiveWords sensitiveWords){
    //
    //    return Result.ok(sensitiveWordsService.save(sensitiveWords));
    //}

    @Log(operationModule = "敏感词库", operationType = Constants.INSERT)
    @PostMapping("/insert")
    public Result add(@RequestBody BaseSensitiveWords sensitiveWords){
        return Result.ok(sensitiveWordsService.insert(sensitiveWords));
    }

    @Log(operationModule = "敏感词库", operationType = Constants.UPDATE)
    @PostMapping("/update")
    //@OperLog(type = 1, clazz = LogMapper.class, convertClass = BaseSensitiveWords.class)
    public Result update(@RequestBody BaseSensitiveWords sensitiveWords){
        return Result.ok(sensitiveWordsService.update(sensitiveWords));
    }

    @PostMapping("/findById/{id}")
    public Result getgetSensitiveWordsId(@PathVariable long id){
        BaseSensitiveWords words = sensitiveWordsService.findById(id);
        return Result.ok(words);
    }


}
